<?php

class Model_DbTable_Matricebr extends Zend_Db_Table
{
    protected $_name = 'matricebr';
    /**
		Recupererle point de la muraille par son id
     */
    public function getMatricebr($id) 
    {
        $id = (int)$id;
        $row = $this->fetchRow('id = ' . $id);
        if (!$row) {
            throw new Exception("Count not find row $id");
        }
        return $row->toArray();    
    }
    
	public function getInfoMatricebr() {
		$db = Zend_Db::factory('PDO_MYSQL', array ('host' => '127.0.0.1', 'username'
		 => 'root', 'password' => '@dmin2010gmv', 'dbname'   => 'gmv'));
		$select = $db->select()
		->from(array('a' => 'matricebr'))
		->join(array('p' => 'proprietaire'), 'p.idproprietaire = a.proprietaire_idproprietaire')
		->join(array('e' => 'bassinderetention'), 'e.idbassinderetention = a.bassinderetention_idbassinderetention');
		$rows = $select->query()->fetchAll();
        $arbre = array();$arbre['total'] = count($rows);$arbre['rows'] = $rows;
		return $arbre;    
	}
    public function addMatricebr($i,$j, $bassinderetention_idbassinderetention,$proprietaire_idproprietaire,$type)
    {
            $data = array(
            'i' => $i,
        	'j' => $j,
            'bassinderetention_idbassinderetention' => $bassinderetention_idbassinderetention,
        	'proprietaire_idproprietaire' => $proprietaire_idproprietaire,
        	'type' => $type,
        );
        $this->insert($data);
    }

    
    public function updateMatricebr($id, $i, $j, $bassinderetention_idbassinderetention,$proprietaire_idproprietaire,$type)
    {
         $data = array(
            'i' => $i,
        	'j' => $j,
         	'bassinderetention_idbassinderetention' => $bassinderetention_idbassinderetention,
        	'proprietaire_idproprietaire' => $proprietaire_idproprietaire,
        	'type' => $type,
        );
        $this->update($data, 'id = '. (int)$id);
        
    }
    
    
	function deleteMatricebr($id) {
		$this->delete ( 'id =' . ( int ) $id );
	}
	
    public function getBassin($bassinderetention_idbassinderetention) {
        $bassinderetention_idbassinderetention = (int)$bassinderetention_idbassinderetention;
        $db = Zend_Db::factory('PDO_MYSQL', array ('host' => '127.0.0.1', 'username'
		 => 'root', 'password' => '@dmin2010gmv', 'dbname'   => 'gmv'));
		$select = $db->select()
		->from(array('m' => 'matricebr'))
		->join(array('b' => 'bassinderetention'), 'b.idbassinderetention = m.bassinderetention_idbassinderetention');
		$rows = $select->query()->fetchAll();
		$mat = array();
        $mat['total'] = count($rows);
        $mat['rows'] = $rows;
		return $mat;  
    }
    
    public function getProprietaire($proprietaire_idproprietaire) {
        $proprietaire_idproprietaire = (int)$proprietaire_idproprietaire;
        $db = Zend_Db::factory('PDO_MYSQL', array ('host' => '127.0.0.1', 'username'
		 => 'root', 'password' => '@dmin2010gmv', 'dbname'   => 'gmv'));
		$select = $db->select()
		->from(array('m' => 'matricebr'))
		->join(array('p' => 'proprietaire'), 'p.idproprietaire = m.proprietaire_idproprietaire');
		$rows = $select->query()->fetchAll();
		$mat = array();
        $mat['total'] = count($rows);
        $mat['rows'] = $rows;
		return $mat;  
    }
    
    /**
     * 
     * @return  
     */
    public function getAllMatricebr() {    
        $all = $this->fetchAll();
        $matricebr = array();
        $matricebr['total'] = count($all->toArray());
        $matricebr['rows'] = $all->toArray();

        
        return $matricebr ;
    }    
    
  public function getCoordonneee($imin,$imax,$jmin,$jmax) {    
 		$select = $this ->select()
             -> from('matricebr')
             -> where('i > ?', $imin)
             -> where('i <= ?', $imax)
             -> where('j > ?', $jmin)
             -> where('j <= ?', $jmax);

        $all = $this -> fetchAll($select);
        $matricebr = array();
        $matricebr['total'] = count($all->toArray());
        $matricebr['rows'] = $all->toArray();
        //$result = $this -> fetchAll($select);
        return $matricebr;
    }
    
    

    
   
    
}
